parser grammar AnalexBreakParser;

options {
  language = Java;
  tokenVocab = AnalexCLexer;
}

@header {
  package Practica8.Sintactico;
}

@members {
  private ArrayList<String> errors = new ArrayList<String>();
  public void displayRecognitionError(String[] tokenNames, RecognitionException e) {
    String hdr = getErrorHeader(e);
    String msg = getErrorMessage(e, tokenNames);
    errors.add(hdr + " " + msg);
  }
   
  public ArrayList<String> getErrors() {
    return errors;
  }
}

entrada [boolean inbucle]: (sentencias[inbucle])*;


sentencias [boolean inbucle]
  : whileblock[inbucle]
  | ifblock [inbucle]
  | breakstatement [inbucle]
  ;

whileblock [ boolean inbucle ]
  : KEYWORD_WHILE LEFT_PAREN ID RIGHT_PAREN { inbucle = true; } block[inbucle] {inbucle = false;};

block [ boolean inbucle ]
  : LEFT_BRACE (sentencias[inbucle])* RIGHT_BRACE;

ifblock [ boolean inbucle ]
  : KEYWORD_IF LEFT_PAREN ID RIGHT_PAREN block[inbucle];

breakstatement [ boolean inbucle ]
  : KEYWORD_BREAK SEPARADOR 
    { if (inbucle)
        System.out.println("Break SI está dentro de bucle");
      else
        System.out.println("Break NO está dentro de bucle");
    };